package cn.com.infohold.smartcity.parent;

import android.app.Application;
import android.content.Context;

import common.base.BaseApplication;
import library.utils.Logger;
import library.utils.Utils;

/**
 * Created by Mr.Fan on 2016-4-7.
 */
public class ParentApplication extends Application implements Thread.UncaughtExceptionHandler {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);

    }

    @Override
    public void onCreate() {
        super.onCreate();
        if (Utils.isRemoteProcess(this))
            return;

//        if (Utils.isDebuggable(this)) {
//            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
//                    .detectCustomSlowCalls() //API等级11，使用StrictMode.noteSlowCode
//                    .detectDiskReads()
//                    .detectDiskWrites()
//                    .detectNetwork()   // or .detectAll() for all detectable problems
//                    .penaltyDialog() //弹出违规提示对话框
//                    .penaltyLog() //在Logcat 中打印违规异常信息
//                    .penaltyFlashScreen() //API等级11
//                    .build());
//            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
//                    .detectLeakedSqlLiteObjects()
//                    .detectLeakedClosableObjects() //API等级11
//                    .penaltyLog()
//                    .penaltyDeath()
//                    .build());
//        }

        BaseApplication.create(this, this);
    }

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        Logger.debug(e);
        e.printStackTrace();
        exit();
    }

    public static void quit() {
        exit();
    }

    public static void exit() {
        BaseApplication.exit();
    }

}
